
$(function() {

	$("input[id^='name_s']:visible").autocomplete(Test.emp_name);
		
	$("input[id^='t3_']:visible").datepicker({
		numberOfMonths: 2,
		dateFormat: 'yy-mm-dd',
		showButtonPanel: true
	});
	
	$("input[id^='t4_']:visible").datepicker({
		numberOfMonths: 2,
		dateFormat: 'yy-mm-dd',
		showButtonPanel: true
	});
	
	$("select[id^='state_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
});

function idcard(s) {
	if (s == null || s.trim() == '') {
		return false;
	}

	var value = s.trim();
	var regex;

	// 本地号码 13760120595
	regex = /^(\d{15})$/
	if (regex.test(value)) {
		return true;
	}
	
	regex = /^(\d{18})$/
	if (regex.test(value)) {
		return true;
	}
	
	regex = /^(\d{17})[a-zA-Z]{1}$/
	if (regex.test(value)) {
		return true;
	}
	
	regex = /^[a-zA-Z]{1}(\d{6,10})$/
	if (regex.test(value)) {
		return true;
	}
	
	regex = /[\d,|a-z|A-Z|\-|(|)]{6,12}$/
	if (regex.test(value)) {
		return true;
	}
	

	return false;
}

function validate_add() {
	var _vv_option = {
		rules: {
			idcard: {
				remote: "emp.php?do=Emp.ajax_exist_idcard",
				required: true
			}
		},
		messages: {
			idcard: {
				remote: jQuery.format("{0} 已经存在")
			}
		},
		errorPlacement: function(label, element) {
			label.insertAfter(element);
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	};
	
	var validator = $("#form_add").validate(_vv_option);

	return validator.form();
}

function validate_add2() {
	var validator = $("#form_add").validate({
		rules: {
			code: {
				ab: 8,
				remote: "emp.php?do=Emp.ajax_exist"
			},
			name: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 4
			}
		},
		errorPlacement: function(label, element) {
			label.insertAfter(element);
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});

	return validator.form();
}

var Emp = {	
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				
				var form = $("#form_add")[0];
	
				var body = { };
				// body.code = form.code.value;
				body.source = form.source.value;
				body.date = form.date.value;
				
				body.name = form.name.value;
				
				body.idcard = form.idcard.value;
				body.indate = form.indate.value;
				body.fzjg = form.fzjg.value;
				
				body.sex = form.sex.value;
				body.birthday = form.birthday.value;
							
				body.province = form.province.value;
				body.city = form.city.value;
				body.district = form.district.value;
	
				body.address = form.address.value;
				
				if (is_null(body.source)) {
					alert("应聘途径不能为空，请选择一个或手动输入！");
					return;
				}
				
				if (!idcard(body.idcard)) {
					alert("请输入正确的15位或18位身份证号码！");
					return;
				}
				
				if (!confirm("确认是否添加？")) {
					return false;
				}
				
				if (!validate_add()) {
					alert("员工信息已经存在，请点重新入职即可！");
					return false;
				}
	
				$(this).dialog("close");
	
				$.post('emp.php?do=Emp.addPost', body, function(data) {
					$(result).html(data);
				});
			},
			
			"重新入职": function() {
				var form = $("#form_add")[0];
	
				var body = { };
				// body.code = form.code.value;
				body.source = form.source.value;
				body.date = form.date.value;
				
				body.name = form.name.value;
				
				body.idcard = form.idcard.value;
				body.sex = form.sex.value;
				body.birthday = form.birthday.value;
							
				body.province = form.province.value;
				body.city = form.city.value;
				body.district = form.district.value;
	
				body.address = form.address.value;
				
				if (is_null(body.source)) {
					alert("应聘途径不能为空，请选择一个或手动输入！");
					return;
				}
				
				if (!idcard(body.idcard)) {
					alert("请输入正确的15位或18位身份证号码！");
					return;
				}
				
				if (!confirm("确认是否重新入职？")) {
					return false;
				}
				
				if (validate_add()) {
					alert("员工信息不存在，请点添加！");
					return false;
				}
	
				$(this).dialog("close");
	
				$.post('emp.php?do=Emp.rejob', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'emp.php?do=Emp.edit&id=' + id;
		var c2 = 'emp.php?do=Info.edit&id=' + id;
		var c3 = 'emp.php?do=EmpJob.update&id=' + id;

		var c4 = 'emp.php?do=Info.view&id=' + id;

		var c5 = 'emp.php?do=Emp.role&id=' + id;
		var c6 = 'emp.php?do=Emp.priv&id=' + id;
		var c9 = 'info.php?do=Customize.emp&id=' + id;

		var c7 = 'emp.php?do=Emp.leave&id=' + id;
		var c8 = 'emp.php?do=Emp.card&id=' + id;

		var a1 = ['基本信息', 'url', 'Emp.dialog_base', '700x410'];
		var a2 = ['个人资料', 'url', 'Emp.dialog_info', '700x400'];
		// var a3 = ['入职信息', 'url', 'Emp.dialog_job', '650x400'];

		var a4 = ['员工信息', 'url', 'Common.dialog_view_', '650x450'];

		var a5 = ['分配角色', 'url', 'Emp.dialog_role', '650x500'];
		var a6 = ['分配权限', 'url', 'Emp.dialog_priv', '650x500'];
		var a9 = ['定制功能', 'url', 'Emp.dialog_func', '650x500'];

		var a7 = ['员工离职', 'url', 'Emp.dialog_leave', '650x450'];
		
		var a8 = ['工卡信息', 'url', 'Common.dialog_view_', '650x450'];

		if (status == 1) {
			var b1 = ['权限复制', 'url', 'Emp.dialog_copy', '600x360'];
			var b3 = ['工作交接', 'url', 'Emp.dialog_connect', '600x360'];
			
			var d1 = 'emp.php?do=Admin.copy&id=' + id;
			var d3 = 'emp.php?do=Admin.connect&id=' + id;
			
			var s = c1 + ", " + c2 + ", " + d1 + ", " + d3 + ", " + c5 + ", " + c6 + ", " + c9 + ", " + c7;
			return this.popup_(e, [a1, a2, b1, b3, a5, a6, a9, a7], s);
		}

		if (status == 2) {
			var s = c1 + ", " + c5 + ", " + c6 + ", " + c7;
			return this.popup_(e, [a1, a5, a6, a7], s);
		}

		if (status == 3) {		
			var b1 = ['重新入职', 'url', 'Emp.dialog_rejoin', '600x360'];
			
			var b2 = ['权限转移', 'url', 'Emp.dialog_move', '600x360'];
			var b3 = ['权限复制', 'url', 'Emp.dialog_copy', '600x360'];			
			var b4 = ['工作交接', 'url', 'Emp.dialog_connect', '600x360'];
			
			var d1 = 'emp.php?do=Admin.move&id=' + id;
			
			var d2 = 'emp.php?do=Admin.move&id=' + id;
			var d3 = 'emp.php?do=Admin.copy&id=' + id;
			var d4 = 'emp.php?do=Admin.connect&id=' + id;
			
			var s = c1 + ", " + d1 + ", " + d2 + ", " + d3 + ", " + d4;
			return this.popup_(e, [a1, b1, b2, b3, b4], s);
		}

		var s = c1 + ", " + c5 + ", " + c6;
		return this.popup_(e, [a1, a5, a6], s);	
	},

	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var c3 = 'emp.php?do=Emp.view&view_qr=1&id=' + id;
		var a3 = ['二维码', 'url', 'Common.dialog_view_', '600x400'];
		
		var ss = 'emp.php?do=Emp.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Emp.dialog_ss', '400x200'];
		
		s += ", " + c3 + ", " + ss;
		
		a.push(a3);
		a.push(bb);
		
		return popup(e, a, s);
	},

	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=88', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'emp.php?do=Emp.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_base: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.ajax_edit', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
						// body.code = form.code.value;
						body.name = form.name.value;
						body.zjm = form.zjm.value;
						body.engname = form.engname.value;
			
						body.office = form.office.value;
						body.dept = form.dept.value;
						body.job = form.job.value;
						body.orderby = form.orderby.value;
			
						body.mobile = form.mobile.value;
						body.short = form.short.value;
			
						body.exten = form.exten.value;
			
						body.email = form.email.value;
						body.im = form.im.value;
						body.im_openfire = form.im_openfire.value;
						
						body.book = form.book.value;
						body.state = form.state.value;
						
						body.content = form.content.value;
						body.emp = form.emp.value;
						
						body.status = form.status.value;
						
						$(this).dialog("close");
			
						var url = 'emp.php?do=Emp.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
							// alert("修改成功！");
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_info: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.sex = form.sex.value;
				body.birthday = form.birthday.value;
				
				body.idcard = form.idcard.value;
				body.indate = form.indate.value;
				body.fzjg = form.fzjg.value;
	
				body.nationality = form.nationality.value;
				body.education = form.education.value;
				body.marriage = form.marriage.value;
	
				body.province = form.province.value;
				body.city = form.city.value;
				body.district = form.district.value;
	
				body.address = form.address.value;
				
				body.content = form.content.value;
	
				var url = 'emp.php?do=Info.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					// $(result).html(data);
					$('#userfile').uploadify('upload');
				});
			}
		});
	
		dialog_edit(url, title, xy);
	}, 

	dialog_job: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				
				body.emp = form.emp.value;
				body.name = form.name.value;
				body.t1 = form.t1.value;
							
				$(this).dialog("close");
	
				var url = 'emp.php?do=EmpJob.updatePost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					// $(result).html(data);
					alert("修改成功！");
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},

	dialog_leave: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.ajax_emp', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"离职": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
						body.t2 = form.t2.value;
						body.content = form.content.value;
			
						$(this).dialog("close");
			
						var url = 'emp.php?do=Emp.leavePost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	}, 

	dialog_role: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=73', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"分配角色": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var foo = [];
						$('#role option').each(function(i, n) {
							foo[i] = $(n).val();
						});

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.list = foo.join(",");

						$(this).dialog("close");

						var url = 'emp.php?do=Emp.rolePost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
							// alert("角色更新成功。");
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {			
				_error();
			}
		});	
	}, 

	dialog_priv: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=74', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"分配权限": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var foo = [];
						$('#priv option').each(function(i, n) {
							foo[i] = $(n).val();
						});

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.list = foo.join(",");

						$(this).dialog("close");

						var url = 'emp.php?do=Emp.privPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
							// alert("权限更新成功。");
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	},
	
	dialog_func: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var foo = [];
				
				$("#selected option").each(function(i, n) {
					foo[i] = $(n).val();
				});
				
				var form = $("#form_edit")[0];

				var body = { };
				body.id = form.id.value;
				body.list = foo.join(",");

				$(this).dialog("close");

				var url = 'info.php?do=CustomizeMy.empPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					// $(result).html(data);
					alert("更新成功！");
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	extra: function (e, id, status) {
		$.cookie('id_', id);

		var c1 = 'emp.php?do=Contract.add&id=' + id;
		var c2 = 'emp.php?do=Family.add&id=' + id;
		var c3 = 'emp.php?do=Education.add&id=' + id;
		var c4 = 'emp.php?do=Work.add&id=' + id;
		var c5 = 'emp.php?do=Exten.add&id=' + id;
		
		var c6 = 'emp.php?do=Info.upload&id=' + id;
		var c7 = 'emp.php?do=Emp.test&id=' + id;
				
		var c9 = 'emp.php?do=Emp.bank2&id=' + id;
		
		var a1 = ['合同信息+', 'url', 'Emp.dialog_contract', '650x420'];
		var a2 = ['家庭关系+', 'url', 'Emp.dialog_family', '650x420'];
		var a3 = ['学习经历+', 'url', 'Emp.dialog_education', '650x420'];
		var a4 = ['工作经历+', 'url', 'Emp.dialog_work', '650x420'];
		var a5 = ['分机信息+', 'url', 'Emp.dialog_exten', '600x420'];
		
		var a6 = ['上传附件+', 'url', 'Common.dialog_upload', '600x420'];
		var a7 = ['拍照', 'url', 'Emp.dialog_test', '600x420'];
				
		var a9 = ['银行帐号+', 'url', 'Emp.dialog_bank', '650x420'];
		
		var s = c1 + ", " + c2 + ", " + c3 + ", " + c4 + ", " + c5 + ", " + c6 + ", " + c9;
		return popup(e, [a1, a2, a3, a4, a5, a6, a9], s);
		
//		var s = c1 + ", " + c2 + ", " + c3 + ", " + c4 + ", " + c5 + ", " + c6 + ", " + c7 + ", " + c9;
//		return popup(e, [a1, a2, a3, a4, a5, a6, a7, a9], s);
	},
	
	dialog_contract: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				
				body.name = form.name.value;
				
				body.t1 = form.date1.value;
				body.t2 = form.date2.value;
				body.day = form.day.value;
				
				body.content = form.content.value;
	
				$.post('emp.php?do=Contract.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	dialog_family: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.name = form.name.value;
				body.relative = form.relative.value;
	
				body.address = form.address.value;
				body.job = form.job.value;
	
				body.tel = form.tel.value;
				body.content = form.content.value;
	
				$.post('emp.php?do=Family.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	}, 

	dialog_education: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.t1 = form.t1.value;
				body.t2 = form.t2.value;
	
				body.school = form.school.value;
				body.address = form.address.value;
				
				body.profession = form.profession.value;
				body.degree = form.degree.value;
				body.content = form.content.value;
	
				$.post('emp.php?do=Education.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	}, 

	dialog_work: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.t1 = form.t1.value;
				body.t2 = form.t2.value;
				
				body.company = form.company.value;
				body.job = form.job.value;
	
				body.tel = form.tel.value;
				body.reason = form.reason.value;
				body.content = form.content.value;
	
				$.post('emp.php?do=Work.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	dialog_mac: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.mac = form.mac.value;
				body.dhcp = form.dhcp.value;
	
				body.ip = form.ip.value;
				body.netmask = form.netmask.value;
	
				body.gw = form.gw.value;
				body.category = form.category.value;
				body.content = form.content.value;
				body.out = form.out.value;
				body.status = form.status.value;
	
				$.post('emp.php?do=Mac.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	dialog_exten: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.exten = form.exten.value;
	
				body.record_in = form.record_in.value;
				body.record_out = form.record_out.value;
	
				$.post('emp.php?do=Exten.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	dialog_test: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				if (!validate_add()) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.exten = form.exten.value;
	
				body.record_in = form.record_in.value;
				body.record_out = form.record_out.value;
	
				$.post('emp.php?do=Exten.addPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	dialog_bank: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
							
				var form = $("#form_add")[0];
	
				var body = { };
				body.id = form.id.value;
				body.bank = form.bank.value;
				body.branch = form.branch.value;
				body.bankcode = form.bankcode.value;
	
				body.province = form.province.value;
				body.city = form.city.value;
				
				body.zone = form.zone.value;
				body.type = form.type.value;
				
				body.name = form.name.value;
				body.code = form.code.value;
				
				body.content = form.content.value;
	
				$.post('emp.php?do=Emp.bankPost', body, function(data) {
					$('#dialog_add').html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	dialog_move: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=79', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.from_emp = form.id.value;
						body.to_emp = form.to_emp.value;
							
						$(this).dialog("close");
			
						var url = 'emp.php?do=Admin.movePost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("更新成功。");
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_copy: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=79', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_add")[0];
			
						var body = {};
						body.from_emp = form.from_emp.value;
						body.to_emp = form.to_emp.value;
							
						$(this).dialog("close");
			
						var url = 'emp.php?do=Admin.copyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("更新成功。");
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_connect: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=79', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_add")[0];
			
						var body = {};
						body.type = form.type.value;
						body.from_emp = form.from_emp.value;
						body.to_emp = form.to_emp.value;
							
						$(this).dialog("close");
			
						var url = 'emp.php?do=Admin.connectPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("更新成功。");
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	download: function (key) {
		if (!confirm("确认是否下载？若下载，建议先另存，再打开。")) {
			return false;
		}
		
		var url = 'emp.php?do=Info.download&key=' + key;
		jswin(url, 'save', '800x600');
		
		return true;
	},
	
	file: function (id, key) {
		if (!confirm("确认是否删除？")) {
			return false;
		}
		
		var c6 = 'emp.php?do=Info.upload&id=' + id;
		
		var url = 'emp.php?do=Info.file';
		var body = { };
		body.key = key;
		
		$.post(url, body, function(data) {
			// alert(data);
			$.get(c6, function(data) {
				$('#dialog_edit').html(data);
			});
		});
		
		return true;
	},

	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'emp.php?do=Emp.delete' + p2;
		var c2 = 'emp.php?do=Emp.card';
		
		var c3 = 'emp.php?do=Emp.xls&xls=1' + p2;
		var c4 = 'emp.php?do=Emp.xls&xls=2' + p2;
		var c5 = 'emp.php?do=Emp.xls&xls=3' + p2;
		var c6 = 'emp.php?do=Emp.xls&xls=4' + p2;
		var cb = 'emp.php?do=Emp.xls&xls=6' + p2;
		
		var c7 = 'emp.php?do=Info.xls&xls=5' + p2;
		var ca = 'emp.php?do=Info.xls' + p2;
		
		var c8 = 'emp.php?do=Emp.txt' + p2;
		var c9 = 'emp.php?do=Emp.ldif' + p2;
		
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		var a2 = ['打印信息', 'url', 'Emp.dialog_card', '650x400'];
		
		var a3 = ['导出信息', 'url', 'jswin', '1024x768'];
		var aa = ['导出资料', 'url', 'jswin', '1024x768'];
		
		var a4 = ['社保', 'url', 'jswin', '1024x768'];
		var a5 = ['工行办卡', 'url', 'jswin', '1024x768'];
		var a6 = ['中信办卡', 'url', 'jswin', '1024x768'];
		var ab = ['农商行卡', 'url', 'jswin', '1024x768'];
		
		var a7 = ['中控考勤机', 'url', 'jswin', '1024x768'];
		
		var a8 = ['导出vcf', 'url', 'Emp.dialog_txt', '650x400'];
		var a9 = ['导出ldif', 'url', 'Emp.dialog_txt', '650x400'];
		
		var s = c1 + ", " + c2 + ", " + c3 + ", " + c4 + ", " +  c5 + ", " + c6 + ", " + cb + ", " + c7 + ", " + c8 + ", " + c9 + ", " + ca;

		return popup(e, [a1, a2, a3, a4, a5, a6, ab, a7, a8, a9, aa], s);
	},

	dialog_card: function (url, title, xy) {
		var c = new Array();
		$("input[name^='c_1_']").each(function() {
			if ($(this).attr("checked")) {
				var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
				c.push(s);
			}
		});
		
		var cc = c.join("&");	
		
		$.cookie('body', cc);
		
		var s = url + "&" + cc;
		
		$('#dialog_view').dialog('option', 'buttons', { 		
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"打印": function() { 
				$.jPrintArea("#dialog_view");
			}
		});

		dialog_view(s, title, xy);
	},
	
	dialog_txt: function (url, title, xy) {
		var c = new Array();
		$("input[name^='c_']").each(function() {
			if ($(this).attr("checked")) {
				var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
				c.push(s);
			}
		});
		
		var cc = c.join("&");
		
		var s = url + "&" + cc;
		
		jswin(s, 'jswin', '1024x768');
	}
};